package com.tts.hbdao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.tts.hbentity.UserLine;

/**
 * Data access object (DAO) for domain model class UserLine.
 * 
 * @see com.tts.hbentity.UserLine
 * @author MyEclipse Persistence Tools
 */

public class UserLineDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(UserLineDAO.class);
	// property constants
	public static final String USER_LINE_STATUS = "userLineStatus";
	public static final String USER_LINE_BOOK_MSG = "userLineBookMsg";
	public static final String USER_LINE_DEAL_MSG = "userLineDealMsg";

	public void save(UserLine transientInstance) {
		log.debug("saving UserLine instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(UserLine persistentInstance) {
		log.debug("deleting UserLine instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public UserLine findById(java.lang.Integer id) {
		log.debug("getting UserLine instance with id: " + id);
		try {
			UserLine instance = (UserLine) getSession().get(
					"com.tts.hbdao.UserLine", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(UserLine instance) {
		log.debug("finding UserLine instance by example");
		try {
			List results = getSession()
					.createCriteria("com.tts.hbdao.UserLine").add(
							Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding UserLine instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from UserLine as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserLineStatus(Object userLineStatus) {
		return findByProperty(USER_LINE_STATUS, userLineStatus);
	}

	public List findByUserLineBookMsg(Object userLineBookMsg) {
		return findByProperty(USER_LINE_BOOK_MSG, userLineBookMsg);
	}

	public List findByUserLineDealMsg(Object userLineDealMsg) {
		return findByProperty(USER_LINE_DEAL_MSG, userLineDealMsg);
	}

	public List findAll() {
		log.debug("finding all UserLine instances");
		try {
			String queryString = "from UserLine";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public UserLine merge(UserLine detachedInstance) {
		log.debug("merging UserLine instance");
		try {
			UserLine result = (UserLine) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(UserLine instance) {
		log.debug("attaching dirty UserLine instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(UserLine instance) {
		log.debug("attaching clean UserLine instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}